<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.1.js"></script>
<script type="text/javascript">
	$(function (){
		var v = "queryByBookName";
		function change(val){
			v = val;
		}
		$("input[type=radio]").each(function(){
			$(this).click(function(){
				change(this.value);
			});
		});
		$("input[type=button]").click(function(){
	        var ur = '/book/' + v + '.action';
	        /* var params = $("#bookForm").serialize(); 
	        $.ajax({  
	            url:ur,  
	            type:'post',  
	            data:params,  
	            dataType:'json',  
	            success:function (data) { 
	            	var obj = $.parseJSON(data.result);
	            	var str = "";
	            	for (var i = 0; i < obj.length; i++) {
						str += "<tr>";
						str += "<td>"+obj[i].ISBN+"</td>"
						str += "<td>"+obj[i].bookName+"</td>"
						str += "<td>"+obj[i].author+"</td>"
						str += "<td>"+obj[i].publisher+"</td>"
						date = new Date(obj[i].date.time).toLocaleDateString();
						str += "<td>"+date+"</td>"
						str += "<td>"+obj[i].sal+"</td>"
						str += "<td>"+obj[i].count+"</td>"
						str += "</tr>"
					}
	            	$("tbody").html(str);
	            }  
	        });  */
	        
	        var params = $("#bookForm").serialize();
	        $.post(ur,params,function(data, json) {
				// 复选框被选中时的回调函数
				var obj = $.parseJSON(data);
            	var str = "";
            	for (var i = 0; i < obj.length; i++) {
					str += "<tr>";
					str += "<td>"+obj[i].ISBN+"</td>"
					str += "<td>"+obj[i].bookName+"</td>"
					str += "<td>"+obj[i].author+"</td>"
					str += "<td>"+obj[i].publisher+"</td>"
					date = new Date(obj[i].date.time).toLocaleDateString();
					str += "<td>"+date+"</td>"
					str += "<td>"+obj[i].sal+"</td>"
					str += "<td>"+obj[i].count+"</td>"
					str += "</tr>"
				}
            	$("tbody").html(str);
			});
		});  
	});
</script>
</head>
<body>
	<form name="f" method="post" id="bookForm">
		关键字：<input type="text" name="keywords"/><br>
		<input type="radio" name="keyword" id="bookName" value="queryByBookName" checked="checked">按书名查询
		<input type="radio" name="keyword" id="author" value="queryByAuthor">按作者查询
		<input type="radio" name="keyword" id="publisher" value="queryByPublisher">按出版社查询
		<br>
		<input type="button" value="查询">
	</form>
	<table>
		<caption>图书列表</caption>
		<thead>
			<tr>
				<td>ISBN</td>
				<td>图书名称</td>
				<td>图书作者</td>
				<td>出版社</td>
				<td>出版时间</td>
				<td>售价</td>
				<td>库存</td>
			</tr>
		</thead>
		<tbody></tbody>
	</table>
	<s:debug></s:debug>
</body>
</html>